#ifndef __MSVSENDHANDLER_H__
#define __MSVSENDHANDLER_H__

#include <e32base.h>
#include <msvapi.h>
//#include <MuiuMsvSingleOpWatcher.h>  // CMsvSingleOpWatcherArray in oem

#include "msvhandler.h"
#include "YuebaoBuffer.h"

class MMsvObserver;

class CSmsSendHandler : public CMsvHandler
{
public:
    enum
    {
        EMaxTelephoneNumberLength = 30
    };
    static CSmsSendHandler* NewL( MMsvObserver& aObserver );
    static CSmsSendHandler* NewLC( MMsvObserver& aObserver );

    ~CSmsSendHandler( );
    void SendToL( const TDesC& aRecipient, const TDesC& aText );

public:
    // from CMsvHandler
    TBool IsIdle( );

public:
    // from MMsvSessionObserver
    void HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3 );

protected:
    // from CActive
    void RunL( );

protected:
    explicit CSmsSendHandler( MMsvObserver& aObserver );
private:
    void ConstructL( );
    void CreateNewMessageL( );
    TBool SetupSmsHeaderL( );
    void PopulateMessageL( TMsvEntry& aMsvEntry );
    TBool InitializeMessageL( );
    TBool MoveMessageEntryL( TMsvId aTarget );
    void SetScheduledSendingStateL( CMsvEntrySelection& aSelection );
    void HandleChangedEntryL( TMsvId aEntryId );

private:
    enum TPhase
    {
        EIdle, EWaitingForCreate, EWaitingForMove, EWaitingForScheduled, EWaitingForSent, EWaitingForDeleted
    };

    // Member variables
    TPhase iPhase;
    YuebaoBuffer< EMaxTelephoneNumberLength > iRecipientsTelNum;
    YuebaoBuffer< 140 > iText; // This is a fixed amount of message data
};

#endif // __MSVSENDHANDLER_H__
